
// Copyright (C) 2009-2011 Luca Piccioni
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//   
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;

namespace Derm.Render
{
	/// <summary>
	/// Orthographic camera.
	/// </summary>
	public class OrthoCamera : ICamera
	{
		#region Constructors
		
		/// <summary>
		/// OrthoCamera constructor.
		/// </summary>
		public OrthoCamera()
		{
			
		}
		
		#endregion

		#region Viewing Fustrum Management

		/// <summary>
		/// Viewing fustrum minimum range.
		/// </summary>
		public float MinRange
		{
			get { return (mMinRange); }
			set
			{
				// Store viewing fustrum minimum range
				mMinRange = value;
			}
		}

		/// <summary>
		/// Viewing fustrum maximum range.
		/// </summary>
		public float MaxRange
		{
			get { return (mMaxRange); }
			set
			{
				// Store viewing fustrum maximum range
				mMaxRange = value;
			}
		}

		/// <summary>
		/// Ortho view fustrum minimum range.
		/// </summary>
		private float mMinRange = -1.0f;

		/// <summary>
		/// Ortho view fustrum minimum range.
		/// </summary>
		private float mMaxRange = +1.0f;

		#endregion
		
		#region ICamera Implementation

		/// <summary>
		/// Setup camera projection.
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="RenderContext"/>
		/// </param>
		/// <remarks>
		/// This routine implementation is the characteristic of this class. It defines an orthographic
		/// projection, using the camera viewing fustrum.
		/// </remarks>
		public void SetupProjection(RenderContext ctx)
		{
			float pTop =	+1.0f;
			float pBottom = -1.0f;
			float pRight =	+1.0f;
			float pLeft =	-1.0f;

			// Construct projection matrix
			ProjectionMatrix projection = new ProjectionMatrix();

			projection.SetOrtho(pLeft, pRight, pBottom, pTop, MinRange, MaxRange);
			// Set projection matrix
			ctx.Projection = projection;
		}

		/// <summary>
		/// Apply this perspective view.
		/// </summary>
		/// <param name="ctx">
		/// A <see cref="RenderContext"/>
		/// </param>
		/// <remarks>
		/// Derived classes defines the viewing transformation overriding this routine.
		/// </remarks>
		public void SetupView(RenderContext ctx)
		{
			// Start from identity model view
			ctx.Model.SetIdentity();
		}
		
		/// <summary>
		/// Pick from this perspective view.
		/// </summary>
		/// <param name="rPipeline">
		/// </param>
		/// <param name="x">
		/// A <see cref="System.Int32"/>
		/// </param>
		/// <param name="y">
		/// A <see cref="System.Int32"/>
		/// </param>
		public void PickView(RenderPipeline rPipeline, int x, int y)
		{
			
		}
		
		#endregion
	}

}
